/**
 * 
 */
package com.google.code.cisx.servlets;

import java.sql.Connection;

import javax.persistence.EntityManager;

import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.jpa.JpaEntityManager;
import org.eclipse.persistence.sessions.Session;

/**
 * Uses EclipseLink Specific APIs to return an underlying {@link Connection} instance.
 * 
 * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
 * @version $Id: EclipseLinkDevelopmentServlet.java 259 2008-11-29 13:18:52Z rahul.thakur.xdev $
 * @since 1.0
 */
public class EclipseLinkDevelopmentServlet extends DevelopmentServlet {

  private static final long serialVersionUID = -4423409879268078148L;

  /**
   * {@inheritDoc}
   * 
   * @see com.google.code.cisx.servlets.DevelopmentServlet#getConnection()
   */
  @Override
  Connection getConnection() {
    EntityManager entityManager = getEntityManager();
    JpaEntityManager eclipseLinkEM = (JpaEntityManager) entityManager;
    Session activeSession = eclipseLinkEM.getActiveSession();
    Connection connection = (Connection) ((AbstractSession) activeSession).getAccessor().getConnection();
    return connection;
  }

}
